<template>
    <!-- 分包结算 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)" v-btnPermission="'bm_025_add_01'">新增</a-button>
            <a-alert class="mb12" type="info" show-icon>
                <template slot="message">
                    <span>
                     应完结算份数：<a>{{ SummaryData.number || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                         应完已完份数(项目报出)：<a>{{ SummaryData.shouldAccomplishNumber || 0 }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        结算完成率(应完已完)：<a>{{ SummaryData.settlementRate || 0 }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        已完份数(项目报出)：<a>{{ SummaryData.accomplishNumber || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        终审完成份数:<a>{{ SummaryData.finallyAuditNumber || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                         现合同额(含税)(万元):<a>{{ SummaryData.nowContractAmount || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                         项目初审值(含税)(万元):<a>{{ SummaryData.projectFirstValue || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        公司终审值(含税)(万元):<a>{{ SummaryData.comFinalAmount || 0}}</a>
                    </span>
                      <a-divider type="vertical" />
                    <span>
                        审减率:<a>{{ SummaryData.reductionAmountRate || 0}}</a>
                    </span>
                </template>
            </a-alert>
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :page-keys="['pageNum', 'pageSize','totalSize']"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
            <template slot="contractAmount" slot-scope="text, record">
                {{toFixedFn(record.contractAmount)}}
            </template>
            <template slot="projectFirstValue" slot-scope="text, record">
                {{toFixedFn(record.projectFirstValue)}}
            </template>
            <template slot="comFinalAmount" slot-scope="text, record">
                {{toFixedFn(record.comFinalAmount)}}
            </template>
            <template slot="comReductionAmountRate" slot-scope="text, record">
                {{toFixedFn(record.comReductionAmountRate)}}
            </template>
            <template slot="bomAuditedAmount" slot-scope="text, record">
                {{toFixedFn(record.bomAuditedAmount)}}
            </template>
            <template slot="action" slot-scope="text, record">
                     <MoreButton>
                    <a @click="handleManage(0, record,true)" v-btnPermission="'bm_025_loo_04'">查看</a>
                    <span
                        v-if="record.isAuto*1===0 && record.status*1===0" v-btnPermission="'bm_025_edi_02'">
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                    <span
                        v-if="record.isAuto*1===1 && (record.status*1===0 || record.status*1===5)" v-btnPermission="'bm_025_edi_02'">
                        <a @click="handleManage(3, record)">填报</a>
                    </span>
                    <span v-if="record.status*1===3" v-btnPermission="'bm_025_tov_05'">
                        <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
                    </span>
                    <span
                    v-if="(record.isAuto*1===0 && record.status*1===0) || record.status*1===4"
                    v-btnPermission="'bm_025_del_03'">
                    <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
                </span>

                     </MoreButton>
                </template>
                <template slot="status" slot-scope="text">
                    <list-status :status="text + ''"></list-status>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import {getSettlementList,getTopTotal,delSettlementList,settlementRevoke} from '@/api/businessAffairs/settlement'
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
// import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商单位
import SelectSubcontractorCode from '@/components/Select/SelectSubcontractorCode' // 分包商
import { typeListApproval,category} from './model'
import listStatus from './listStatus.vue'
import Template from '@/views/construction/gantt/template.vue'
const searchArr = [
    // 搜索框
    // {name: '所属分公司', valueKey: 'branchComId', type: SelectSubCompany},
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {name: '所属项目',keyValue: 'branchComId',valueKey: 'projectId',type: SelectProject},
    {name: '分包商单位',type: 'input',value: 'subcontractorName'},
    {name: '合同名称',type: 'input',value: 'contractName'},
    {name: '终审编号',type: 'input',value: 'comCode'},
    {name: '填报人',type: 'input',value: 'modifiedName'},
    {name: '类别',value: 'type',type: 'select',data: category},
    {name: '项目提交时间',type: 'dateRange',value: 'modifiedTime',
        attr: {
            rangeFormat: ['startTime', 'endTime']
        }
    },
    {name: '分公司提交时间',type: 'dateRange',value: 'bomCommissionTime',
        attr: {
            rangeFormat: ['bomStartTime', 'bomEndTime']
        }
    }, 
    {name: '终审完成时间',type: 'dateRange',value: 'commissionTime',
        attr: {
            rangeFormat: ['finallyStartTime', 'finallyEndTime']
        }
    },
    {name: '状态',value: 'status',type: 'select',data: typeListApproval}
]

const columns = [
    {title: '所属分公司',dataIndex: 'branchComName',ellipsis: true,width: 150,},
    {title: '所属项目',dataIndex: 'projectName',ellipsis: true,width: 150,},
    {title: '分包商单位',dataIndex: 'subpackageUnitName',ellipsis: true,width: 150,},
    {title: '合同名称',dataIndex: 'contractName',ellipsis: true,width: 150,},
    {title: '合同额(万元)',dataIndex: 'contractAmount',ellipsis: true,width: 150,scopedSlots:{ customRender: 'contractAmount'}},
    {title: '类别',dataIndex: 'typeName',ellipsis: true,width: 150,},
    {title: '项目初审值(含税)(万元)',dataIndex: 'projectFirstValue',ellipsis: true,width: 250,scopedSlots:{ customRender: 'projectFirstValue'}},
    {title: '分公司审核值(含税)(万元)',dataIndex: 'bomAuditedAmount',ellipsis: true,width: 250,scopedSlots:{ customRender: 'bomAuditedAmount'}},
    {title: '公司终审值(含税)(万元)',dataIndex: 'comFinalAmount',ellipsis: true,width: 250,scopedSlots:{ customRender: 'comFinalAmount'}},
    {title: '审减率',dataIndex: 'comReductionAmountRate',ellipsis: true,width: 250,scopedSlots:{ customRender: 'comReductionAmountRate'}},
    {title: '终审编号',dataIndex: 'comCode',ellipsis: true,width: 250,},
    {title: '填报人',dataIndex: 'modifiedName',width: 200,ellipsis: true},
    {title: '填报时间',dataIndex: 'modifiedTime',ellipsis: true, width: 150,},
    {title: '状态',dataIndex: 'status',scopedSlots: { customRender: 'status' },width: 150,},
    {title: '操作',dataIndex: 'action',width: '280px',align: 'center',scopedSlots: { customRender: 'action' },  fixed: 'right',}
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable,
        listStatus,
        Template,
        SelectSubcontractorCode
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            queryParam: {}, // 查询参数
            statistics: { totalAutoContractFee: 0, totalTentativelyUpProfitFee: 0, totalTentativelyUpRate: 0 }, //统计
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, { param: this.queryParam});
                this.getSummaryData(this.queryParam)
                return getSettlementList(requestParameters).then((res) => {
                 return res;
                })
            },
            removeApi: { remove: delSettlementList, invalid: settlementRevoke},// api
            SummaryData:{
                number:0,     //应完结算份数
                shouldAccomplishNumber:0, //应完已完份数(项目报出
                settlementRate:0,  //结算完成率
                accomplishNumber:0, // 已完份数(项目报出):
                finallyAuditNumber:0,   // 	终审完成份数
                nowContractAmount:0,   // 现合同额(含税)(万元)
                projectFirstValue:0,   // 项目初审值(含税)(万元)
                comFinalAmount:0,   //公司终审值(含税)(万元)
                reductionAmountRate:0, //统计审减率
            }    //汇总
        }
    },
    methods: {
        toFixedFn(data){
            if(data || data == 0){
                return data.toFixed(2)
            }else{
             return ''
            }
        },
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
       async getSummaryData(requestParameters) {
           let reqData = await getTopTotal(requestParameters);
            if(reqData.code=='0'){
                this.SummaryData = reqData.data;
            }   
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateSettlement',
                query
            })
        }
    },
}
</script>
